package com.water.service.Impl;

import com.water.context.BaseContext;
import com.water.entity.WaterUsage;
import com.water.exception.ParameterException;
import com.water.mapper.WaterUsageMapper;
import com.water.service.WaterUsageService;
import com.water.vo.WaterUsageVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: city_water
 * @description:
 * @author: lydms
 * @create: 2024-05-11 20:52
 **/

@Service
public class WaterUsageServiceImpl implements WaterUsageService {

    @Autowired
    private WaterUsageMapper waterUsageMapper;

    /**
     * 查询水表使用量
     *
     * @return
     */
    @Override
    public WaterUsageVo getInfo() {
        Long userId = BaseContext.getCurrentId();
        if (userId == null){
            throw new ParameterException("用户未登录");
        }
        //查询
        WaterUsage waterUsage = waterUsageMapper.getInfo(userId);

        WaterUsageVo waterUsageVo = new WaterUsageVo();
        BeanUtils.copyProperties(waterUsage,waterUsageVo);

        return waterUsageVo;
    }
}
